import java.io.*;
import java.util.Scanner;

public class CopyFile {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你想要复制文件的路径");
        String srcPath = sc.next();
        System.out.println("请输入你要复制到的目标路径");
        String destPath = sc.next();

        File srcFile = new File(srcPath);
        if(!srcFile.isFile()) {
            System.out.println("你输入的路径不合法");
            return;
        }
        File destFile = new File(destPath);
        if(!destFile.getParentFile().isDirectory()) {
            System.out.println("你输入的路径不合法");
            return;
        }

        try(InputStream inputStream = new FileInputStream(srcFile); OutputStream outputStream = new FileOutputStream(destFile)) {
           byte[] bytes = new byte[1024];
           while(true) {
               int n = inputStream.read(bytes);
               if (n == -1) {
                   break;
               }
               outputStream.write(bytes, 0, n);
           }
        }  catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
